﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace ERP.Manager.BusinessServices
{
    public class EmailServices
    {
        /// 邮件发送方法
        /// </summary>
        /// <param name="email">email地址</param>
        /// <param name="subject">邮件标题</param>
        /// <param name="content">邮件内容</param>
        /// <returns></returns>
        public bool SendEmail(string email, string subject, string content)
        {
            string fromSMTP = "smtp.163.com";        //邮件服务器
            string fromEmail = "cqjusheng@163.com";      //发送方邮件地址
            string fromEmailPwd = "1818158";//发送方邮件地址密码
            string fromEmailName = "重庆";   //发送方称呼
            //新建一个MailMessage对象
            MailMessage aMessage = new MailMessage(fromEmail, email, subject, content);
            aMessage.BodyEncoding = System.Text.Encoding.UTF8;
            aMessage.IsBodyHtml = true;
            aMessage.Priority = MailPriority.High;
            aMessage.ReplyTo = new MailAddress("wanghemin168@gmail.com", fromEmailName); //邮件回复地址

            SmtpClient smtp = new SmtpClient();
            smtp.Host = fromSMTP;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.EnableSsl = false;
            smtp.Credentials = new NetworkCredential(fromEmail, fromEmailPwd); //发邮件的EMIAL和密码
            smtp.Port = 25;
            try
            {
                smtp.Send(aMessage);
                return true;
            }
            catch (Exception )
            {
                return false;
                //throw ex;
            }
        } 
    }
}
